$(function(){
    // console.log("wwww")
    $.ajax({
        url:'./php/teacherPage.php',
        type:'post',
        dataType:"json"
    }).done((result)=>{
        let strs=template("demo",{result});
        console.log(result)
        $("#t").html(strs);
  
    })
})

// 修改后重新加载
function reload(){
    $.ajax({
        url:'./php/teacherPage.php',
        type:'post',
        dataType:"json"
    }).done((result)=>{
        // console.log(result);
        let strs=template("demo",{result});
        // console.log(result)
        $("#t").html(strs);
    })
}

//模态框默认值
function reTeacher(obj){
    var teacherId= $(obj).val();
    console.log(teacherId)
    var data={
        "teacherId":teacherId
    };
    $.ajax({
        //当teacherid=
        url:'./php/showUpdateTeach.php',
        type:'post',
        data:data,
        dataType:"json"
    }).done((result)=>{
        $("#teacherno1").val(result.teacher.teacherId);
        $("#teachername1").val(result.teacher.teacherName);
        $("#username1").val(result.teacher.username);

    })
 
}


// 老师更新完成
function updatedTeach(){
    let tef=$("#tef")[0];
    let formData= new FormData(tef);
}

// 查老师
function seachteacher(){
    toastr.options = {"timeOut": "5000"}
    let tfs=$("#tfs")[0];//查询表单
    let formData= new FormData(tfs);

    $.ajax({
        url:"./php/searchteacher.php",
        method:"post",
        data:formData,
        dataType: "json",
        contentType: false,
        processData: false,
    }).done((data)=>{
        console.log(data)
        if(!data){
            toastr.error("没有该教师");
        }
        var str2 = template("demo_",{data});
        $("#t").html("");
        $("#t").html(str2);
    })

}

// 禁用 status=0

function stop(obj){
    let teacherId=$(obj).val();
    // console.log(teacherId);
    let data={
        "teacherId":teacherId
    }
    $.ajax({
        url:"./php/teacherStop.php",
        type:"post",
        data:data,
        dataType:"json",
        success:function(result){
            console.log(result)
            reload();
            toastr.success("禁用成功");
            if(!result){
                toastr.error("禁用失败");
            }
        }
    })

}

// 开启 teacherStart
function start(obj){
    let teacherId=$(obj).val();
    // console.log(teacherId);
    let data={
        "teacherId":teacherId
    }
    $.ajax({
        url:"./php/teacherStart.php",
        type:"post",
        data:data,
        dataType:"json",
        success:function(result){
            console.log(result)
            reload();
            toastr.success("开启成功");
            if(!result){
                toastr.error("开启失败");
            }
        }
    })

}

function password(obj){
    let teacherId=$(obj).val();
    console.log(teacherId);
    let data={
        "teacherId":teacherId
    }
    console.log(data)
    $.ajax({
        url:"./php/password.php",
        type:"post",
        data:data,
        dataType:"json",
        success:function(result){
            console.log(result)
            reload();
            toastr.success("密码重置成功");
            if(!result){
                toastr.error("重置失败");
            }
        }
    })

}